//
//  ChatMessageIconCell.m
//  YSTChatUIKit
//
//  Created by 王文文 on 2018/2/13.
//  Copyright © 2018年 王文文. All rights reserved.
//

#import "ChatMessageIconCell.h"
#import "ChatMessageFrame.h"

@interface ChatMessageIconCell()

/**
 头像
 */
@property(nonatomic, strong) UIImageView *headImageView;

/**
 昵称
 */
@property(nonatomic, strong) UILabel *nameLabel;

/**
 信息内容
 */
@property(nonatomic, strong) UIImageView *messageIconView;

/**
 气泡
 */
@property(nonatomic, strong) UIButton *airView;

@end

@implementation ChatMessageIconCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self.contentView addSubview:self.imageBtn];
    }
    return self;
}

- (void)imageBtnClick:(UIButton *)btn {
    if (btn.currentBackgroundImage == nil) {
        return;
    }
   
}

-(void)setMessageFrame:(ChatMessageFrame *)MessageFrame {
    _MessageFrame = MessageFrame;
    
    self.headImageView.frame = MessageFrame.headViewFrame;
    self.nameLabel.frame = MessageFrame.nameLabelFrame;
    self.messageIconView.frame = MessageFrame.iconFrame;
    self.airView.frame = MessageFrame.airViewFrame;
    NSString *norImageName  = MessageFrame.message.userType == userTypeOther ? @"chat_send_nor" : @"chat_receive_nor";
    NSString *seleImageName = MessageFrame.message.userType == userTypeOther ? @"chat_send_p" : @"chat_receive_p";
    UIImage *norImage  = [UIImage resizebleImageWithName:norImageName];
    UIImage *seleImage = [UIImage resizebleImageWithName:seleImageName];
    [self.airView setBackgroundImage:norImage forState:UIControlStateNormal];
    [self.airView setBackgroundImage:seleImage forState:UIControlStateHighlighted];
    if (MessageFrame.message.messageContent) {
        //如果有信息
        
    } else {
         self.messageIconView.image = MessageFrame.message.picture;
    }
}

#pragma mark - Getter
- (UIButton *)imageBtn {
    if (nil == _imageBtn) {
        _imageBtn = [[UIButton alloc] init];
        [_imageBtn addTarget:self action:@selector(imageBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        _imageBtn.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 0);
        _imageBtn.layer.masksToBounds = YES;
        _imageBtn.layer.cornerRadius = 5;
        _imageBtn.clipsToBounds = YES;
    }
    return _imageBtn;
}

@end
